package com.jwaoo.mobile.view.account;

import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.dx.as.ToolBarOptions;
import com.dx.as.common.CommonUtils;
import com.dx.as.fragment.TFragment;
import com.jwaoo.chat.UserInfo;
import com.jwaoo.mobile.R;
import com.jwaoo.mobile.view.account.update.UpdateActivity;
import com.jwaoo.mobile.view.setting.SettingActivity;
import com.jwaoo.mobile.view.user.IUserView;
import com.jwaoo.mobile.view.user.presenter.UserPresenter;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by jwaoo on 2017/11/23.
 */

public class MeFragment extends TFragment implements IUserView {
    private ScrollView scrollview;
    private Handler handler = new Handler(){};
    private UserPresenter userPresenter;
    private ImageView img_bg;
    private TextView tv_nickname;
    @Override
    public void initView() {
        findView(R.id.btn_setting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), SettingActivity.class);
                startActivity(intent);
            }
        });
        findView(R.id.btn_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), UpdateActivity.class);
                startActivity(intent);
            }
        });
        tv_nickname = findView(R.id.tv_nickname);
        findView(R.id.view_option).setVisibility(View.GONE);
        scrollview = findView(R.id.scrollview);
        img_bg = findView(R.id.img_bg);
        handler.post(new Runnable() {
            @Override
            public void run() {
                scrollview.fullScroll(View.FOCUS_DOWN);
            }
        });
        userPresenter = new UserPresenter(getActivity(),this);
        setToolBar(null);
        userPresenter.getContactInfo(CommonUtils.getIMAccount());

    }

    @Override
    public int setLayoutI() {
        return R.layout.activity_user;
    }

    @Override
    public void dataOpion() {

    }

    @Override
    public void initRpo() {

    }
    @Override
    public void getUserInfo(final UserInfo userInfo) {
        if (userInfo != null){
            handler.post(new Runnable() {
                @Override
                public void run() {
                    ImageLoader.getInstance().displayImage(userInfo.getAvatar(),img_bg);
                    tv_nickname.setText(userInfo.getNickname());
                }
            });

        }
    }

}
